package com.hanyxx.coll;

import lombok.Data;

/**
 * @author layman
 * @date 2021/2/24
 */
public class MyLinkedList {
    //首节点
    private Node first;
    //尾节点
    private Node last;

    public void add(Object obj){
        if(first==null){
            //说明该元素存于首节点上
            Node firstNode = new Node();
            firstNode.setPrevious(null);
            firstNode.setObj(obj);
            firstNode.setNext(null);

            //此时该LinkedList只存了一个元素，所以首尾节点都设置为首节点
            first = firstNode;
            last = firstNode;
        }else{
            //存入的不是首节点，则该元素存于首节点之后，指向前一个节点的last
            Node node=new Node();
            node.setPrevious(last);
            node.setObj(obj);
            node.setNext(null);

            //将链表的last改为node
            last = node;
        }
    }

    public static void main(String[] args) {
        String str1 = new String("ABC");
        String str2 = new String("ABC");
        System.out.println(str1.hashCode());
        System.out.println(str2.hashCode());
    }
}
// 节点类
@Data
class Node {
    //前驱节点
    private Object previous;
    //存储的数据
    private Object obj;
    //后续节点
    private Object next;
}
